package info.jimao.newsdk.results;

import org.json.JSONObject;

/**
 * 不带数据的执行结果类，
 */
public class NoDataResult {
    protected boolean success;
    protected String message;
    protected String errorCode;
    protected String accessToken;

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public NoDataResult(boolean success, String message) {
        super();
        this.success = success;
        this.message = message;
    }

    public NoDataResult(String jsonString) {
        try {
            JSONObject root = new JSONObject(jsonString);
            this.success = !root.isNull("Success") && root.getBoolean("Success");
            this.message = !root.isNull("Message") ? root.getString("Message") : "";
            this.errorCode = !root.isNull("ErrorCode") ? root.getString("ErrorCode") : "";
            this.accessToken = !root.isNull("AccessToken") ? root.getString("AccessToken") : "";
        } catch (Exception e) {
            this.success = false;
            this.message = "数据转换异常";
        }
    }
}
